using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MyPhotoIndex.Controls;

namespace MyPhotoIndex.Plugins.Share.pic4u
{
    public partial class LoginForm : FormTemplate
    {
        public string UserName
        {
            get { return UserNameTextBox.Text; }
            set { UserNameTextBox.Text = value; }
        }

        public string Password
        {
            get { return PasswordTextBox.Text; }
            set { PasswordTextBox.Text = value; }
        }

        public LoginForm(string userName)
        {
            InitializeComponent();

            UserNameTextBox.TextChanged += new EventHandler(TextChangedHandler);
            PasswordTextBox.TextChanged += new EventHandler(TextChangedHandler);
            UserName = userName;
            base.OkButtonEnabled = false;

            this.Load += new EventHandler(LoginForm_Load);
        }

        void LoginForm_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(UserName) == false)
            {
                PasswordTextBox.Focus();
            }
        }

        void TextChangedHandler(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(UserNameTextBox.Text.Trim()) ||
                String.IsNullOrEmpty(PasswordTextBox.Text.Trim()))
            {
                base.OkButtonEnabled = false;
            }
            else
            {
                base.OkButtonEnabled = true;
            }
        }
    }
}